#pragma once
#include <iostream>
#include <cstring>

//抽象原型类 
class Object{
public:
	virtual Object* clone() = 0;
};


//附件类 
class Attachment{
public:
	void download(){
		std::cout << "下载附件" << std::endl;
	}
};


//具体类Email
class Email : public Object{
public:
	//构造 
	Email(){
		this->attachment = new Attachment();
	}
	
	//析构
	~Email(){
		if(this->attachment!=nullptr){
			delete this->attachment;
		}
	}
    //深克隆的拷贝构造函数 
	Email(const Email& email){
		//只适用于Attachment内无成员指针变量，如有指针变量仍需在Attachment里面定义(深克隆的)拷贝构造 
		this->attachment = new Attachment();
		memcpy(this->attachment,email.attachment,sizeof(Attachment));
	}
	
	//深克隆 
	Object* clone(){ 
		return new Email(*this);
	}
	
	// //浅克隆
	// Object* clone(){
	// 	return new Email(*this);
	// }
	
	//获取附件 
	Attachment* getAttachment(){
		return this->attachment;
	}
	
	//显示 
	void display(){
		std::cout << "查看邮件" << std::endl;
	}
private:
	Attachment *attachment = nullptr;
}; 